package com.icebartech.core.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 常用入参校验
 * @author Administrator
 *
 */
public class ParamValidateUtil {
	
	private static String emailPattern = "^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$";
	private static String ipPattern = "([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}";
//	private static String mobilePattern = "^((13[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$";
	private static String mobilePattern = "^\\d{11}$";
	private static String pwdPattern = "^[a-zA-Z0-9]{6,12}$";
	private static String userNamePattern = "^[a-zA-Z0-9]{6,32}$";
	private static String idCardPattern = "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)";

	/**
	 * 邮箱格式校验
	 * @param email
	 * @return
	 */
	public static boolean validateEmail(String email){
		return validatePattern(email, emailPattern);
	}
	
	public static boolean validatePwd(String pwd){
		return validatePattern(pwd, pwdPattern);
	}
	
	/**
	 * ip地址校验
	 * @param ip
	 * @return
	 */
	public static boolean validateIp(String ip){
		return validatePattern(ip, ipPattern);
	}
	
	/**
	 * 手机号码格式校验
	 * @param phone
	 * @return
	 */
	public static boolean validatePhone(String phone){
		return validatePattern(phone, mobilePattern);
	}
	
	public static boolean validateUserName(String userName){
		return validatePattern(userName, userNamePattern);
	}
	
	public static boolean validateIdCard(String idCard){
		return validatePattern(idCard, idCardPattern);
	}
	
	
	public static boolean validatePattern(String value, String pattern){
		Pattern p = Pattern.compile(pattern);
		Matcher matcher = p.matcher(value);
		return matcher.matches();
	}
    
    public static void main(String[] args) {
        System.out.println(validateIdCard("25411418900415262x"));
    }
}
